<script type="text/javascript" src="<?=base_url()?>resource/js/layer/layer.js"></script>
<script type="text/javascript">
    /**
     * 新增角色
     * @constructor
     */
    function AddRole(){
        layer.open({
            type: 1,
            title: '新增角色',
            area: ['540px', '200px'], //宽高
            content: $('#roleDiv')
        });
        $('#roleForm').attr('action','<?=blang_url('users/member/AddRole')?>');
        $('#id').val('');
        $('#name_en').val('');
        $('#name_ch').val('');
    }
    /**
     * 编辑角色
     * @constructor
     */
    function UpdateRole(id){
        layer.open({
            type: 1,
            title: '编辑角色',
            area: ['540px', '200px'], //宽高
            content: $('#roleDiv')
        });
        $('#roleForm').attr('action','<?=blang_url('users/member/UpdateRole')?>');
        var index=layer.load(2);
        $.post("<?=blang_url('ajax/ajax_two/GetRoleInfo')?>",{'id':id},function(data){
            if(data){
                layer.close(index);
                var roleData=JSON.parse(data);
                $('#id').val(roleData.id);
                $('#name_en').val(roleData.name_en);
                $('#name_ch').val(roleData.name_ch);
            }
        });
    }
    /**
     * 提交验证
     * @constructor
     */
    function SendVerify(){
        var id=$('#id').val();
        var name_en= $.trim($('#name_en').val());
        var name_ch= $.trim($('#name_ch').val());
        var in_array_en='';
        var in_array_ch='';
        if(name_ch==''){
            alert('角色中文名称不能为空');
            return false;
        }
        if(name_en==''){
            alert('角色英文名称不能为空');
            return false;
        }
        if(id == ''){
            $('.name_en').each(function(key, val){
                if (name_en == $(this).val()) {
                    in_array_en = name_en;
                }
            });
            $('.name_ch').each(function(key, val){
                if (name_ch == $(this).val()) {
                    in_array_ch = name_ch;
                }
            });
            if(in_array_en){
                alert('<'+name_en+'>英文名称已经存在');
                return false;
            }
            if(in_array_ch){
                alert('<'+name_ch+'>中文名称已经存在');
                return false;
            }
        }
    }
</script>

<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
          <h1><?=lang('menu_yhgl')?></h1>
          <?=$this->breadcrumb->generateHTML();?><span>:<?= $roleInfo['name'] ?>【<?= $roleInfo['name_en'] ?>】</span>
          <div class="pull-right">
              <a href="javascript:void(0);" title="新增角色"  onclick="AddRole()" class="btn btn-primary"><i class="fa fa-plus"></i></a>
          </div>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-list"></i>角色列表</h3>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover oms-table">
                  <thead>
                    <tr>
                        <th class="text-left">ID</th>
                        <th class="text-left">角色名</th>
                        <th class="text-right" style="width:20%;">操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php if($roleData): foreach ($roleData as $key=>$row):?>
                    <tr>
                        <td class="text-left"><?=$row['id']?></td>
                        <td class="text-left">
                            <input type="hidden" class="name_en" value="<?=$row['name_en']?>">
                            <input type="hidden" class="name_ch" value="<?=$row['name_ch']?>">
                            <?=$row['name']?>
                        </td>
                        <td class="text-right">
                            <?php if($row['is_update']==1){?>
                            <a class="btn btn-primary btn-sm" href="javaScript:void(0)" onclick="UpdateRole(<?=$row['id']?>)" title="编辑"><i class="fa fa-edit"></i></a>
                            <?php }?>
                            <a  class="btn btn-oms btn-sm" href="<?=blang_url('users/member/SetPermission?id='.$row['id'])?>">权限设置</a>
                        </td>
                    </tr>
                    <?php endforeach; else:?>
                        <tr><td colspan="6" class="emptyNumber"><?=lang('public_mygdsj')?>....</td></tr>
                    <?php endif; ?>
                </tbody>
                </table>
                <?php if($pageShow):?>
                <div class="page">
                    <?=$pageShow?>
                </div>
                <?php endif;?>
            </div>
          </div>
        </div>
    </div>
  
    <div class="ct_content" style="display: none;margin-left: 20px;margin-top: 10px;" id="roleDiv">
    <form action="" method="post" id="roleForm">
        <table cellspacing="0" style="border-collapse: collapse;width: 500px;">
            <tr>
                <th>中文名称：</th>
                <td><input type="text" id="name_ch" name="name_ch" size="40"></td>
            </tr>
            <tr>
                <th>英文名称：</th>
                <td><input type="text" id="name_en" name="name_en" size="40"></td>
            </tr>
            <tr align="center">
                <td colspan="2">
                    <input type="hidden" id="id" name="id">
                    <input type="submit" onclick="return SendVerify()" value="提交">
                </td>
            </tr>
        </table>
    </form>
</div>

</div>